public class MS_17_12 {
    TreeNode dummyHead = new TreeNode(-1);
    TreeNode prev = null;
    public TreeNode convertBiNode(TreeNode root) {
        inorder(root);
        return dummyHead.right;
    }

    private void inorder(TreeNode root) {
        if(root == null) {
            return;
        }
        inorder(root.left);
        if(prev == null) {
            prev = root;
            dummyHead.right = prev;
        }else {
            prev.right = root;
            prev = root;
        }
        root.left = null;
        inorder(root.right);
    }
}
